package edu.ecu.seng6270.goa.ropa;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;

import net.miginfocom.swing.MigLayout;

/**
 * ROPA Application Main Class
 */
public class ROPAMain {

	private JFrame frmVplReprintOrder;
	JPanel cards = new JPanel(new CardLayout());
	String myCustomerID;
	
	private Order pendingOrder;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ROPAMain window = new ROPAMain();
					window.frmVplReprintOrder.setVisible(true);
					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public ROPAMain() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmVplReprintOrder = new JFrame();
		frmVplReprintOrder.setTitle("VPL Reprint Order Processing");
		frmVplReprintOrder.getContentPane().setBackground(new Color(255, 255, 255));
		frmVplReprintOrder.setBounds(100, 100, 760, 540);
		frmVplReprintOrder.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmVplReprintOrder.getContentPane().setLayout(new MigLayout("", "[744px,center]", "[116px][346px]"));
		
		// Header Panel
		JPanel headerPanel = new JPanel();
		headerPanel.setBackground(new Color(255, 255, 255));
		frmVplReprintOrder.getContentPane().add(headerPanel, "cell 0 0,growx,aligny top");
		headerPanel.setLayout(new MigLayout("", "[495px,grow]", "[50px,grow,fill][50px]"));
		
		JLabel vplName = new JLabel("Vilkomir Photo Labs");
		vplName.setBackground(new Color(255, 255, 0));
		vplName.setFont(new Font("Tahoma", Font.BOLD, 48));
		vplName.setHorizontalAlignment(SwingConstants.CENTER);
		vplName.setOpaque(true);
		headerPanel.add(vplName, "cell 0 0,grow");
		
		JLabel vplSlogan = new JLabel("Your #1 Source for Quality Photo Processing");
		vplSlogan.setForeground(new Color(255, 255, 255));
		vplSlogan.setBackground(new Color(0, 0, 128));
		vplSlogan.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 20));
		vplSlogan.setHorizontalAlignment(SwingConstants.CENTER);
		vplSlogan.setOpaque(true);
		headerPanel.add(vplSlogan, "cell 0 1,grow");
		
		frmVplReprintOrder.getContentPane().add(cards, "cell 0 1,growx,aligny top");

		moveToCard("loginPanel");

	}
	
	void moveToCard(String cardName) {
		
		CardLayout cl = (CardLayout) cards.getLayout();
		Boolean exists = false;

		for (Component co : cards.getComponents()) {
			if (co.getName().equals(cardName)) {
				exists = true;
				break;
			}
		}

		if (!exists) {
			if (cardName.equals("loginPanel")) {
				LoginPanel c = new LoginPanel(this);
				c.setName(cardName);
				cards.add(c, cardName);
			} else if (cardName.equals("existingOrderPanel")) {
				ExistingOrderPanel c = new ExistingOrderPanel(this);
				c.setName(cardName);
				cards.add(c, cardName);
			} else if (cardName.equals("orderTypePanel")) {
				OrderTypePanel c = new OrderTypePanel(this);
				c.setName(cardName);
				cards.add(c, cardName);
			} else if (cardName.equals("customOrderPanel")) {
				AltCustomOrderPanel c = new AltCustomOrderPanel(this);
				c.setName(cardName);
				cards.add(c, cardName);
			} else if (cardName.equals("expressOrderPanel")) {
				ExpressOrderPanel c = new ExpressOrderPanel(this);
				c.setName(cardName);
				cards.add(c, cardName);
			} else if (cardName.equals("checkoutPanel")) {
				CheckoutPanel c = new CheckoutPanel(this);
				c.setName(cardName);
				cards.add(c, cardName);
			}
		}
		
		cards.validate();
		cl.show(cards, cardName);
	}

	//////////////////////////////
	//	Getters and Setters		//
	//////////////////////////////
	
	public String getMyCustomerID() {
		return myCustomerID;
	}

	public void setMyCustomerID(String myCustomerID) {
		this.myCustomerID = myCustomerID;
	}

	public Order getPendingOrder() {
		return pendingOrder;
	}

	public void setPendingOrder(Order pendingOrder) {
		this.pendingOrder = pendingOrder;
	}
	
	
	
}
